package cn.yuysaln.trigger.job;

import cn.yuysaln.domain.activity.model.valobj.ActivitySkuStockKeyVO;
import cn.yuysaln.domain.activity.service.IRaffleActivitySkuStockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class UpdateActivitySkuStockJob {
    @Resource
    private IRaffleActivitySkuStockService skuStock;
    @Scheduled(cron = "0/5 * * * * ?")
    public void exec(){
        try {
            ActivitySkuStockKeyVO activitySkuStockKeyVO = skuStock.takeQueueValue();
            log.info("【定时任务】---正在获取延迟队列内容进行消费");
            if (null == activitySkuStockKeyVO) return;
            skuStock.updateActivitySkuStock(activitySkuStockKeyVO.getSku());
            log.info("【定时任务】---更新活动sku库存成功！ sku:{} activityId:{}", activitySkuStockKeyVO.getSku(), activitySkuStockKeyVO.getActivityId());
        }catch (Exception e){
            log.error("【定时任务】---更新活动sku库存失败", e);
        }
    }
}
